﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using PiControls.Controls.myTabControl;

namespace PiControls.Controls.DriveUI
{
    public partial class FormAddDrive: UserControl
    {



        public FormAddDrive()
        {
            InitializeComponent();

       
        }

        Color SecondaryColor = Color.FromArgb(255, 51, 153);
        Color PrimaryColor = Color.FromArgb(255, 51, 153);

        public void SetThemeColor(Color color)
        {
            SecondaryColor = color;
            LoadTheme();
        }

        public void SetPrimaryColor(Color color)
        {
            PrimaryColor = color;
            LoadTheme();
        }

        public  void LoadTheme()
        {

            foreach (Control ctrl in GetAllControls(this))
            {

                if (ctrl.GetType() == typeof(Button))
                {
                    Button btn = (Button)ctrl;
                    btn.BackColor = PrimaryColor;
                    btn.ForeColor = Color.White;
                    btn.FlatAppearance.BorderColor = SecondaryColor;
                }

                if (ctrl.GetType() == typeof(GroupBox))
                {
                    GroupBox L_ctrl = (GroupBox)ctrl;
                    L_ctrl.ForeColor = PrimaryColor;

                }
                if (ctrl.GetType() == typeof(Label))
                {
                    Label L_ctrl = (Label)ctrl;
                    L_ctrl.ForeColor = Color.Black;

                }

            }
        }


        private IEnumerable<Control> GetAllControls(Control control)
        {
            foreach (Control child in control.Controls)
            {
                // 返回当前子控件
                yield return child;
                // 递归返回子控件的子控件
                foreach (Control descendant in GetAllControls(child))
                {
                    yield return descendant;
                }
            }
        }


        private void buttonAddDrive_Click(object sender, EventArgs e)
        {
            addDriveSelect addDriveSelectform = new addDriveSelect();
            if (addDriveSelectform.ShowDialog(this) == DialogResult.OK)
            {
                Console.WriteLine("用户选择了："+ addDriveSelectform.AddObjectName);

            }
            else
            {
                Console.WriteLine("用户点击了取消或关闭窗口。");
            }
        }

        private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {
        
        }
    }
}
